import React, {
    Component
} from 'react';
import Header from '../components/common/Header.js'
import './Homepage.css'
class Homepage extends Component{
    constructor(props)
    {
        super(props);
        this.state={
            isLogin:false, // 是否登录
            time:8
        }
    }

    componentDidMount(){
        //window.localStorage.clear();
        if(window.localStorage.getItem('token')===null)
        {
            // window.localStorage.setItem('roleId','1');
            // window.localStorage.setItem('userId','9143');
            // window.localStorage.setItem('token','eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiIiLCJzdWJtaXRDb3VudCI6MCwic3VibWl0VGltZSI6bnVsbCwicmVmcmVzaEV4cERhdGUiOjE1ODQzMjQwOTU1NjUsInJvbGVJZCI6MSwiaXNzIjoiU3d1c3RPSl9KV1QiLCJ2YWlsZENvZGUiOm51bGwsImV4cCI6MTU4NDA2NjY5NSwidXNlcklkIjo5MTQzLCJpYXQiOjE1ODQwNjQ4OTUsIkNMQVNTX1RZUEUiOiJvcmcua2VsYWIuc3d1c3Rvai5jb25zdGFudC5Kc29uV2ViVG9rZW5Db25zdGFudCRKc29uV2ViVG9rZW5DbGFpbXMiLCJ1c2VybmFtZSI6IjUxMjAxNzM0OTQifQ.O1DZ3wOxE72NPYo88cTZIg-8hw7Nuq6BQYRgm8WUswE');
            this.setState({
                isLogin:false
            })
            let timer=setInterval(() => {
                
                this.setState({
                    time:this.state.time-1
                })
                if(this.state.time===1)
                {
                    clearInterval(timer);
                    window.location.href='http://acm.swust.edu.cn'
                }

            }, 1000);
        }else{
            let roleId=window.localStorage.getItem('roleId');
            if(roleId==1||roleId==2)
            {
                window.localStorage.setItem('isStudent',false);
            }else{
                window.localStorage.setItem('isStudent',true);
            }
            this.setState({
                isLogin:true
            })
        }
    }


    render(){
        return(
            <div>
                {
                    this.state.isLogin?<div className="homePage-wrap">
                        <Header />  
                        <header className="homePage-header">
                        </header>
                        <div className="textRunning">
                            <p className="marquee">我们的目标是星辰大海</p>
                        </div>
                        <article className="homePage-content">
                                {this.props.children}     
                        </article>
                        <footer className="homePage-footer">
                        </footer>
                </div>:<div className="no-login">
                   <br />
                   <br />
                   <h4>未登录，请返回<a href="http://acm.swust.edu.cn/">OJ</a>登录,  {this.state.time}秒后自动跳转。</h4>
               </div>
                }
            </div>
            
            
        )
    }
}
export default Homepage;